import os
import sys
import random
import pymysql
import cv2
import numpy as np
from math import pi
from matplotlib import pyplot as plt
from PIL import Image
from decimal import Decimal
from cv2 import CascadeClassifier,face
from PyQt5.QtWidgets import QLineEdit, QMessageBox
from ui_1jinru import Ui_MainWindow as jinru_Ui
from ui_2SingIn import Ui_MainWindow as singin_ui
from ui_3register import Ui_MainWindow as registerone_ui
from ui_4regsiter import Ui_MainWindow as registertwo_ui
from ui_5main import Ui_MainWindow as main_ui
from ui_6punch_the_clock import Ui_MainWindow as punch_ui
from ui_7collection import Ui_MainWindow as collection_ui
from ui_8feedback import Ui_MainWindow as feedback_ui
from ui_9random import Ui_MainWindow as random_ui
from ui_10_useguide import Ui_MainWindow as use_ui
from ui_11financialmedia import Ui_MainWindow as financialmedia_ui
from ui_12financialmedia import Ui_MainWindow as financialmediatwo_ui
from ui_13datawarehousing import Ui_MainWindow as data_ui
from ui_14accountwarehousing import Ui_MainWindow as caccount_ui
from ui_15dataanalysis import Ui_MainWindow as dataanalysis_ui
from PyQt5.QtGui import QIcon, QPixmap
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtCore import QTimer,QDateTime
id_face = []
checklist = []
check_tlist = []
# 进入窗口
class jinruWindow(QtWidgets.QMainWindow,  jinru_Ui):
    # 登录页面跳转信号
    switch_singin = QtCore.pyqtSignal()
    def __init__(self):
        super(jinruWindow, self).__init__()
        self.setupUi(self)
        self.setWindowTitle("睿课人脸识别课堂考勤系统v2.0")
        self.setWindowIcon(QIcon('picture/Logo_2Max.png'))
        self.staraButton.clicked.connect(self.gosingin)
    def gosingin(self):
        self.switch_singin.emit()

# 登录窗口
class singinWindow(QtWidgets.QMainWindow,  singin_ui):
    switch_main = QtCore.pyqtSignal()  # 主界面跳转信号
    switch_registerone = QtCore.pyqtSignal()  # 注册页面_1跳转信号
    def __init__(self):
        super(singinWindow, self).__init__()
        self.setupUi(self)
        self.initUI()
        self.setWindowTitle("睿课人脸识别课堂考勤系统v2.0")
        self.setWindowIcon(QIcon('picture/Logo_2Max.png'))
        self.regButton.clicked.connect(self.goregisterone)

    def initUI(self):
        self.usernametext.setFocus()
        self.usernametext.setPlaceholderText("请输入账户名")  # 提示信息
        self.posswordtext.setPlaceholderText("请输入密码")
        self.posswordtext.setEchoMode(QLineEdit.Password)  # 密码隐藏
        self.loginButton.clicked.connect(self.Check)

    def Check(self):
        user = str(self.usernametext.text())
        pwd = str(self.posswordtext.text())
        db = pymysql.connect(host='localhost', port=3306, user='root', password="369852147", database="facerecognition")
        cursor = db.cursor()
        sql = 'SELECT t_user,t_pwd FROM teacher'
        cursor.execute(sql)
        data = cursor.fetchall()
        cursor.close()
        db.close()
        i=0
        if user == "" or pwd == "":
              QMessageBox.information(self, "睿课", "Tips:账户与密钥不能为空，请仔细核对！")
              return
        elif user != "" and pwd != "":
               while i < int(len(data)):
                   if str(data[i][0]) == user and str(data[i][1]) == pwd:
                       QMessageBox.information(self, "睿课", "账户与密钥匹配成功，即将跳转至主页面！")
                       self.switch_main.emit()
                       return
                   i += 1
               QMessageBox.information(self, "睿课", "error:账户与密钥不匹配，请仔细核对！")
    def goregisterone(self):
        self.switch_registerone.emit()

# 注册窗口_1
class registeroneWindow(QtWidgets.QMainWindow,  registerone_ui):
    switch_registertwo = QtCore.pyqtSignal()  # 注册页面_2跳转信号
    switch_singin = QtCore.pyqtSignal()
    def __init__(self):
        super(registeroneWindow, self).__init__()
        self.setupUi(self)
        self.initUI()
        self.setWindowTitle("睿课人脸识别课堂考勤系统v2.0")
        self.setWindowIcon(QIcon('picture/Logo_2Max.png'))
        self.propose_pushButton.clicked.connect(self.gosingin)
        self.propose_pushButton.clicked.connect(self.close)

    def initUI(self):
        self.number_lineEdit.setFocus()  # 鼠标焦点
        self.number_lineEdit.setPlaceholderText("请设置账户")  # 提示信息
        self.password_lineEdit.setPlaceholderText("密码大于六位（含）")
        self.password_lineEdit.setEchoMode(QLineEdit.Password)#密码隐藏
        self.next_pushButton.clicked.connect(self.emit_next_Button)  # 下一页按钮，检测账户与密码是否合规

    def emit_next_Button (self):
        config = {
            "host": "localhost",
            "user": "root",
            "password": "369852147",
            "database": "facerecognition"
        }
        db = pymysql.connect(**config)
        cursor = db.cursor()
        sql = 'SELECT t_user,t_pwd FROM teacher'
        cursor.execute(sql)
        data = cursor.fetchall()
        t_user = str(self.number_lineEdit.text())
        t_pwd = str(self.password_lineEdit.text())
        t_id = ''
        t_name = ''
        t_sex = ''
        t_school = ''
        t_college = ''
        t_protect = '2'
        i=0
        if t_user == "" or t_pwd == "":
            QMessageBox.information(self, "睿课", "白小泽检查后发现账户或者密钥为空，补填空项！")
        else:
            while i < int(len(data)):
                if str(data[i][0]) == t_user:
                    QMessageBox.information(self, "睿课", "白小泽查阅后发现这个账户名已经被注册了，账户名已被使用！")
                    return
                else:
                    sql = "insert into teacher values('{}', '{}','{}','{}','{}','{}','{}','{}')".format(t_user, t_pwd, \
                     t_id, t_name, t_sex,t_school, t_college, t_protect)
                    cursor.execute(sql)
                    db.commit()  # 提交数据
                    cursor.close()
                    db.close()
                    QMessageBox.information(self, "睿课", "白小泽提示您账号密码设置完成，请完善个人信息！")
                    self.switch_registertwo.emit()
                    return

    def gosingin(self):
        self.switch_singin.emit()

# 注册窗口_2
class registertwoWindow(QtWidgets.QMainWindow,  registertwo_ui):
    switch_singin = QtCore.pyqtSignal()
    def __init__(self):
        super(registertwoWindow, self).__init__()
        self.setupUi(self)
        self.initUI()
        self.setWindowTitle("睿课人脸识别课堂考勤系统v2.0")
        self.setWindowIcon(QIcon('picture/Logo_2Max.png'))
        self.register_pushButton.clicked.connect(self.gosingin)
        self.propose_pushButton.clicked.connect(self.close)

    def initUI(self):
        self.id_lineEdit.setFocus()  # 鼠标焦点
        self.user_lineEdit.setPlaceholderText("重复账户")  # 提示信息
        self.pwd_lineEdit.setPlaceholderText("重复密钥")
        self.pwd_lineEdit.setEchoMode(QLineEdit.Password)  # 密码隐藏

    def gosingin(self):
        db = pymysql.connect(host='localhost', port=3306, user='root', password="369852147", database="facerecognition")
        cursor = db.cursor()
        sql1 = "SELECT * FROM teacher WHERE t_protect=2"
        cursor.execute(sql1)
        data = cursor.fetchall()
        print(data)
        t_user = str(self.user_lineEdit.text())
        t_pwd = str(self.pwd_lineEdit.text())
        t_id = str(self.id_lineEdit.text())
        t_name = str(self.name_lineEdit.text())
        t_sex = str(self.sex_comboBox.currentText())
        t_school = str(self.university_lineEdit.text())
        t_college = str(self.college_lineEdit.text())
        t_protect = '0'
        i = 0
        if t_id == "":
            QMessageBox.information(self, "error", "教职工ID不可以为空，此项为必填信息！")
        elif t_name == "" or t_sex == "" or t_school == "" or t_college == "":
            QMessageBox.information(self, "error", "个人信息表单中有空项，请仔细核对，补填信息！")
        elif t_user == "" or t_pwd == "":
              QMessageBox.information(self, "睿课", "Tips:账户与密钥不能为空，请重新输入！")
              return
        else:
            while i<int(len(data)):
                print("1")
                if str(data[i][0]) == t_user and str(data[i][1]) == t_pwd:
                    sql2 = "DELETE FROM teacher WHERE t_protect=2"
                    cursor.execute(sql2)
                    sql = "insert into teacher values('{}', '{}','{}','{}','{}','{}','{}','{}')".format(data[0][0],\
                                                        data[0][1],t_id, t_name,t_sex,t_school,t_college, t_protect)
                    cursor.execute(sql)
                    db.commit()  # 提交数据
                    cursor.close()
                    db.close()
                    QMessageBox.information(self, "睿课", "注册完成，个人信息已经写入数据库保存！")
                    self.switch_singin.emit()
                    self.close()
                    return
                else:
                    QMessageBox.information(self, "睿课", "error:校验失败，没有找到您输入的账户与密钥！")
                    return

# 主窗口
class mainWindow(QtWidgets.QMainWindow,  main_ui):
    switch_punch = QtCore.pyqtSignal()  # 考勤页面跳转信号
    switch_collection = QtCore.pyqtSignal()  # 信息采集页面跳转信号
    switch_feedback = QtCore.pyqtSignal()  # 意见反馈页面跳转信号
    switch_random = QtCore.pyqtSignal()  # 随机抽检页面跳转信号
    switch_use = QtCore.pyqtSignal()  # 使用指南页面跳转信号
    switch_financialmedia = QtCore.pyqtSignal()  # 融媒体_1页面跳转信号
    switch_financialmediatwo = QtCore.pyqtSignal()  # 融媒体_2页面跳转信号
    switch_datawarehousing = QtCore.pyqtSignal()  # 数据仓储页面跳转信号
    switch_accountwarehousing = QtCore.pyqtSignal()  # 账户仓储页面跳转信号
    switch_dataanalysis = QtCore.pyqtSignal()  # 数据分析页面跳转信号
    def __init__(self):
        super(mainWindow, self).__init__()
        self.setupUi(self)
        self.setWindowTitle("睿课人脸识别课堂考勤系统v2.0")
        self.setWindowIcon(QIcon('picture/Logo_2Max.png'))
        self.pushButton_1.clicked.connect(self.gopunch)
        self.pushButton_2.clicked.connect(self.gocollection)
        self.pushButton_5.clicked.connect(self.gofeedback)
        self.pushButton_6.clicked.connect(self.close)
        self.pushButton_10.clicked.connect(self.gorandom)
        self.pushButton_4.clicked.connect(self.gouse)
        self.pushButton_8.clicked.connect(self.gofinancialmedia)
        self.pushButton_9.clicked.connect(self.gofinancialmediatwo)
        self.pushButton.clicked.connect(self.godatawarehousing)
        self.pushButton_7.clicked.connect(self.goaccountwarehousing)
        self.pushButton_3.clicked.connect(self.godataanalysis)

    def gopunch(self):
        self.switch_punch.emit()
    def gocollection(self):
        self.switch_collection.emit()
    def gofeedback(self):
        self.switch_feedback.emit()
    def gorandom(self):
        self.switch_random.emit()
    def gouse(self):
        self.switch_use.emit()
    def gofinancialmedia(self):
        self.switch_financialmedia.emit()
    def gofinancialmediatwo(self):
        self.switch_financialmediatwo.emit()
    def godatawarehousing(self):
        self.switch_datawarehousing.emit()
    def goaccountwarehousing(self):
        self.switch_accountwarehousing.emit()
    def godataanalysis(self):
        self.switch_dataanalysis.emit()
# 考勤窗口
class punchWindow(QtWidgets.QMainWindow,  punch_ui):
    switch_homemain = QtCore.pyqtSignal()  # 回主页面跳转信号
    recogizer = cv2.face.LBPHFaceRecognizer_create()
    recogizer.read('D:/Face Recognition/pythonProject/Trainingmodel/train.yml')

    def __init__(self):
        super(punchWindow, self).__init__()
        self.setupUi(self)
        self.setWindowTitle("睿课人脸识别课堂考勤系统v2.0")
        self.setWindowIcon(QIcon('picture/Logo_2Max.png'))
        self.statusShowTime()
        self.homeButton.clicked.connect(self.gohomemain)
        self.homeButton.clicked.connect(self.close)
        self.videoButton.clicked.connect(self.Openattendance)
        self.videoButton.clicked.connect(self.datastatistics)
        self.rootButton.clicked.connect(self.rootstate)
        self.exportButton.clicked.connect(self.expordata)

    def expordata(self):
        QMessageBox.information(self, "睿课", "Tips:白小泽正在努力开发中，暂时不支持数据导出功能哦~~~")


    def rootstate(self):
        db = pymysql.connect(host='localhost', port=3306, user='root', password="369852147", database="facerecognition")
        cursor = db.cursor()
        reply = QMessageBox.question(self,
                        "睿课",
                    "重置后所有的学生的状态将变更成未出勤状态，是否修改？",
        QMessageBox.Yes | QMessageBox.No)
        if reply == QMessageBox.Yes:
            sql = "update  punch set state = '0'"
            cursor.execute(sql)
            sql1 = "update  record set record=record-1"
            cursor.execute(sql1)
            db.commit()
            cursor.close()
            db.close()
            QMessageBox.information(self, "睿课", "Tips:白小泽已经将所有学生的考勤状态变更为0，重置成功！")

    def datastatistics(self):
        face = list()
        for s in id_face:
            if s not in face:
                face.append(s)
        db = pymysql.connect(host='localhost', port=3306, user='root', password="369852147", database="facerecognition")
        cursor = db.cursor()
        sql3 = "UPDATE punch SET state='0' "
        sql4 = "UPDATE record SET record=record+1"
        cursor.execute(sql3)
        cursor.execute(sql4)
        db.commit()
        sql = 'SELECT id FROM punch'
        cursor.execute(sql)
        data = cursor.fetchall()
        sql1 = 'SELECT count(id) FROM punch'
        cursor.execute(sql1)
        sum = cursor.fetchall()
        self.sumlabel.setText(str(sum[0][0])+'人')
        i = 0
        num = 0
        print(data)
        while i < int(len(data)):
            j = 0
            while j < int(len(face)):
               if str(data[i][0])==str(face[j]):
                   print(face[j])
                   sql5 = "UPDATE punch SET state='1' WHERE id="+face[j]
                   cursor.execute(sql5)
                   sql6 = "UPDATE student SET attendance=attendance+1 WHERE id="+face[j]
                   cursor.execute(sql6)
                   db.commit()
                   num += 1
               j += 1
            i += 1
        self.comelabel.setText(str(num) + '人')
        self.nolabel.setText(str((sum[0][0])-num) + '人')
        self.latelabel.setText("----")
        cursor.close()
        db.close()
        QMessageBox.information(self, "睿课", "考勤已经结束，出勤信息已经汇总完成！")

    def Openattendance(self):
        cap = cv2.VideoCapture(0)
        while True:
            flag, frame = cap.read()
            self = frame
            if not flag:
                 break
            if ord(' ') == cv2.waitKey(10):
                break
            recogizer = cv2.face.LBPHFaceRecognizer_create()
            recogizer.read('D:/Face Recognition/pythonProject/Trainingmodel/train.yml')
            path = 'D:/Face Recognition/pythonProject/FaceDatabase/'
            names = []
            imagePaths = [os.path.join(path, f) for f in os.listdir(path)]
            for imagePath in imagePaths:
                name = str(os.path.split(imagePath)[1].split('.', 2)[1])
                names.append(name)
            gray = cv2.cvtColor(self, cv2.COLOR_BGR2GRAY)  # 转换为灰度
            face_detector = cv2.CascadeClassifier(
                'D:/opencv/opencv/sources/data/haarcascades/haarcascade_frontalface_alt2.xml')
            face = face_detector.detectMultiScale(gray, 1.1, 5, cv2.CASCADE_SCALE_IMAGE, (100, 100), (300, 300))
            for x, y, w, h in face:
                cv2.rectangle(self, (x, y), (x + w, y + h), color=(0, 0, 255), thickness=2)
                cv2.circle(self, center=(x + w // 2, y + h // 2), radius=w // 2, color=(0, 255, 0), thickness=1)
                # 人脸识别
                ids, confidence = recogizer.predict(gray[y:y + h, x:x + w])
                if confidence > 80:
                    cv2.putText(self, 'unkonw', (x + 10, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (0, 255, 0), 1)
                else:
                    cv2.putText(self, str(names[ids - 1]), (x + 10, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (0, 255, 0), 1)
                    identity = str(names[ids - 1])
                    id_face.append(identity)
            cv2.imshow('In attendance', self)
        cap.release()
        cv2.destroyAllWindows()

    def statusShowTime(self):
        self.Timer = QTimer()  # 自定义QTimer类
        self.Timer.start(1000)  # 每1s运行一次
        self.Timer.timeout.connect(self.updateTime)  # 与updateTime函数连接

    def updateTime(self):
        #获取系统时间，设置显示样式，将获取数据传送给控件
        time=QDateTime.currentDateTime()
        timeplay=time.toString('MM-dd hh:mm:ss dddd')
        self.timelabel.setText(timeplay)

    def gohomemain(self):
        self.switch_homemain.emit()

# 信息采集窗口
class collectionWindow(QtWidgets.QMainWindow,  collection_ui):
    switch_homemain = QtCore.pyqtSignal()  # 回主页面跳转信号
    def __init__(self):
        super(collectionWindow, self).__init__()
        self.setupUi(self)
        self.setWindowTitle("睿课人脸识别课堂考勤系统v2.0")
        self.setWindowIcon(QIcon('picture/Logo_2Max.png'))
        self.collectionButton.clicked.connect(self.collection)
        self.okButton.clicked.connect(self.ok)
        self.noButton.clicked.connect(self.no)
        self.homeButton.clicked.connect(self.gohomemain)
        self.homeButton_2.clicked.connect(self. Ttainingmodel)
        self.homeButton.clicked.connect(self.close)

    def collection(self):
        id = str(self.sidlineEdit.text())
        db = pymysql.connect(host='localhost', port=3306, user='root', password="369852147", database="facerecognition")
        cursor = db.cursor()
        sql1 = 'update pid set pid=pid+1'
        cursor.execute(sql1)
        db.commit()
        sql = 'SELECT pid FROM pid'
        cursor.execute(sql)
        data = cursor.fetchall()
        cursor.close()
        db.close()
        pid = data[0][0]
        if id == "":
            QMessageBox.information(self, "睿课", "请先填写《个人信息表单》中的学号段在进行人脸采集！")
            return
        else:
            cap = cv2.VideoCapture(0)
            num = 1
            while (cap.isOpened()):
                ret_flag, Vshow = cap.read()
                cv2.imshow("Face Collection", Vshow)
                k = cv2.waitKey(1) & 0XFF
                if k == ord(' '):
                    break
                elif k == ord('s') and id !="":
                    cv2.imwrite("D:/Face Recognition/pythonProject/FaceDatabase/" + str(pid) + "." + str(id) + ".jpg", Vshow)
                    print("seccess to save" + str(num) + ".jpg")
                    print("-------------------------")
                    num += 1
        cap.release()
        cv2.destroyAllWindows()
    def ok(self):
        config = {
            "host": "localhost",
            "user": "root",
            "password": "369852147",
            "database": "facerecognition"
        }
        db = pymysql.connect(**config)
        cursor = db.cursor()
        id = str(self.sidlineEdit.text())
        name = str(self.namelineEdit.text())
        cls = str(self.classlineEdit.text())
        sex = str(self.sexlineEdit.text())
        college = str(self.facultylineEdit.text())
        major = str(self.magorlineEdit.text())
        email = str(self.emaillineEdit.text())
        phone = str(self.phonelineEdit.text())
        attendance = str('0')
        state = 0 #state字段有两个参数0，1，2；0表示未出勤，1表示出勤

        if id !="" and name !="" and cls !="" and sex !="" and college !="" and major !="" and phone !="":
            sql = "insert into student values('{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}','{}');".format(id,name,\
                                                                         cls,sex,college,major,email,phone,attendance)
            sql2 = "insert into punch values('{}', '{}', '{}');".format(id,name,state)
            cursor.execute(sql)
            cursor.execute(sql2)
            db.commit()  # 提交数据
            cursor.close()
            db.close()
            QMessageBox.information(self, "睿课", "您的信息采集已经完成！")
            self.sidlineEdit.clear()
            self.namelineEdit.clear()
            self.classlineEdit.clear()
            self.sexlineEdit.clear()
            self.facultylineEdit.clear()
            self.magorlineEdit.clear()
            self.emaillineEdit.clear()
            self.phonelineEdit.clear()
            self.emaillineEdit.setText("无")
        else:
            QMessageBox.information(self, "睿课", "*表示必填项，请完善个人信息！")

    def gohomemain(self):
        self.switch_homemain.emit()

    def no(self):
        self.sidlineEdit.clear()
        self.namelineEdit.clear()
        self.classlineEdit.clear()
        self.sexlineEdit.clear()
        self.facultylineEdit.clear()
        self.magorlineEdit.clear()
        self.emaillineEdit.clear()
        self.phonelineEdit.clear()
        self.emaillineEdit.setText("无")

    def Ttainingmodel(self):
        # 获取图像数组和id标签数组和姓名
        faces, ids = self.getImageAndLabels()
        # 获取训练对象
        recognizer = face.LBPHFaceRecognizer_create()
        recognizer.train(faces, np.array(ids))
        # 保存文件
        recognizer.write("D:/Face Recognition/pythonProject/Trainingmodel/train.yml")
        QMessageBox.information(self, "睿课", "人脸训练已经完成，记得提交《个人信息表单》中的数据！")

    def getImageAndLabels(path):
        # 图片路径
        path = "D:/Face Recognition/pythonProject/FaceDatabase/"
        facesSamples = []
        ids = []
        imagePaths = [os.path.join(path, f) for f in os.listdir(path)]
        # 检测人脸
        face_detector = CascadeClassifier('D:/opencv/opencv/sources/data/haarcascades/haarcascade_frontalface_alt2.xml')
        # 打印数组imagePaths
        print('数据排列：', imagePaths)
        # 遍历列表中的图片
        for imagePath in imagePaths:
            # 打开图片,黑白化
            PIL_img = Image.open(imagePath).convert('L')
            # 将图像转换为数组，以黑白深浅
            img_numpy = np.array(PIL_img, 'uint8')
            # 获取图片人脸特征
            faces = face_detector.detectMultiScale(img_numpy)
            # 获取每张图片的id和姓名
            id = int(os.path.split(imagePath)[1].split('.')[0])
            # 预防无面容照片
            for x, y, w, h in faces:
                ids.append(id)
                facesSamples.append(img_numpy[y:y + h, x:x + w])
            # 打印脸部特征和id
            print('id:', id)
        print('fs:', facesSamples)
        return facesSamples, ids

#数据分析窗口
class dataanalysisWindow(QtWidgets.QMainWindow, dataanalysis_ui):
    switch_homemain = QtCore.pyqtSignal()  # 回主页面跳转信号
    def __init__(self):
        super(dataanalysisWindow, self).__init__()
        self.setupUi(self)
        self.setWindowTitle("睿课人脸识别课堂考勤系统v2.0")
        self.setWindowIcon(QIcon('picture/Logo_2Max.png'))
        self.homeButton.clicked.connect(self.gohomemain)
        self.homeButton.clicked.connect(self.close)
        self.dataButton.clicked.connect(self.dataanalysis)
        self.staraButton.clicked.connect(self.person)
        self.get_datashow()
    def person(self):
        db = pymysql.connect(host='localhost', port=3306, user='root', password="369852147", database="facerecognition")
        cursor = db.cursor()
        id = self.idlineEdit.text()
        if id == '':
            QMessageBox.information(self, "睿课", "白小泽没有检测到可以操作的对象，学号项为空！")
            return
        else:
            self.labellineEdit.clear()
            sql1 = "SELECT attendance FROM student WHERE id=" + id
            cursor.execute(sql1)
            data = cursor.fetchall()
            sql2 = "SELECT record FROM record "
            cursor.execute(sql2)
            records = cursor.fetchall()
            self.attendancelineEdit.setText(str(data[0][0]))
            attendance = int(data[0][0])
            record = int(records[0][0])
            record = (attendance / record) * 100
            record = Decimal(record).quantize(Decimal("0.1"), rounding="ROUND_HALF_UP")
            self.percentagelineEdit.setText(str(record) + '%')
            record = record/10
            record = Decimal(record).quantize(Decimal("0.1"), rounding="ROUND_HALF_UP")
            self.lineEdit_3.setText(str(record))
        if record < 7:
            self.labellineEdit.setText('重点关注')
        cursor.close()
        db.close()
    def dataanalysis(self):
        db = pymysql.connect(host='localhost', port=3306, user='root', password="369852147", database="facerecognition")
        cursor = db.cursor()
        sql = "SELECT id FROM punch WHERE state='0'"
        cursor.execute(sql)
        data = cursor.fetchall()
        sql1 = "SELECT id,name,sex FROM student"
        cursor.execute(sql1)
        data_1 = cursor.fetchall()
        i = 0
        while i < int(len(data)):
            j=0
            while j < int(len(data_1)):
                if str(data[i][0]) == str(data_1[j][0]):
                    self.textEdit.append(str(data_1[j][0])+'    '+str(data_1[j][1])+'     '+str(data_1[j][2]))
                j+=1
            i += 1
        cursor.close()
        db.close()
    def get_dataanalysis_1(self):
        db = pymysql.connect(host='localhost', port=3306, user='root', password="369852147", database="facerecognition")
        cursor = db.cursor()
        sql = "SELECT count(state) FROM punch WHERE state='1'"
        cursor.execute(sql)
        data = cursor.fetchall()
        self.sumlineEdit.setText(str(data[0][0]) + '人')
        sql1 = "SELECT count(state) FROM punch"
        cursor.execute(sql1)
        records = cursor.fetchall()
        cursor.close()
        db.close()
        attendance = int(data[0][0])
        record = int(records[0][0])
        record = (attendance / record) * 100
        record = Decimal(record).quantize(Decimal("0.01"), rounding="ROUND_HALF_UP")
        fig, ax = plt.subplots(figsize=(6, 6), subplot_kw={'projection': 'polar'})
        data = int(record)
        startangle = 90
        x = (data * pi * 2) / 100
        left = (startangle * pi * 2) / 360  # 控制起始位置
        plt.xticks([])
        plt.yticks([])
        ax.spines.clear()
        ax.barh(1, x, left=left, height=1, color='#5DADE2')
        plt.ylim(-3, 3)
        plt.text(0, -3, str(record) + '%', ha='center', va='center', fontsize=42)
        plt.savefig('dataanalysis_1.png', bbox_inches='tight')
        return record
    def get_dataanalysis_2(self):
        db = pymysql.connect(host='localhost', port=3306, user='root', password="369852147", database="facerecognition")
        cursor = db.cursor()
        sql = "SELECT count(state) FROM punch WHERE state='0'"
        cursor.execute(sql)
        data = cursor.fetchall()
        self.absentlineEdit.setText(str(data[0][0]) + '人')
        sql1 = "SELECT count(state) FROM punch"
        cursor.execute(sql1)
        records = cursor.fetchall()
        cursor.close()
        db.close()
        attendance = int(data[0][0])
        record = int(records[0][0])
        record = (attendance / record) * 100
        record = Decimal(record).quantize(Decimal("0.01"), rounding="ROUND_HALF_UP")
        fig, ax = plt.subplots(figsize=(6, 6), subplot_kw={'projection': 'polar'})
        data = int(record)
        startangle = 90
        x = (data * pi * 2) / 100
        left = (startangle * pi * 2) / 360  # 控制起始位置
        plt.xticks([])
        plt.yticks([])
        ax.spines.clear()
        ax.barh(1, x, left=left, height=1, color='r')
        plt.ylim(-3, 3)
        plt.text(0, -3, str(record) + '%', ha='center', va='center', fontsize=42)
        plt.savefig('dataanalysis_2', bbox_inches='tight')
    def get_datashow(self):
        record = self.get_dataanalysis_1()
        self.get_dataanalysis_2()
        self.comelabel.setPixmap(QPixmap("dataanalysis_1.png"))
        self.comelabel.setScaledContents(True)
        self.nolabel.setPixmap(QPixmap("dataanalysis_2.png"))
        self.nolabel.setScaledContents(True)
        if record > 90:
            self.labellineEdit_2.setText("综合评级：优秀")
        elif record > 80:
            self.labellineEdit_2.setText("综合评级：良好")
        elif record > 70:
            self.labellineEdit_2.setText("综合评级：一般")
        else:
            self.labellineEdit_2.setText("综合评级：危险")
    def gohomemain(self):
        self.switch_homemain.emit()

# 意见反馈窗口
class feedbackWindow(QtWidgets.QMainWindow,  feedback_ui):
    switch_homemain = QtCore.pyqtSignal()  # 回主页面跳转信号
    def __init__(self):
        super(feedbackWindow, self).__init__()
        self.setupUi(self)
        self.setWindowTitle("睿课人脸识别课堂考勤系统v2.0")
        self.setWindowIcon(QIcon('picture/Logo_2Max.png'))
        self.homepushButton.clicked.connect(self.gohomemain)
        self.homepushButton.clicked.connect(self.close)
    def gohomemain(self):
        self.switch_homemain.emit()

# 随机抽检窗口
class randomWindow(QtWidgets.QMainWindow,  random_ui):
    switch_homemain = QtCore.pyqtSignal()  # 回主页面跳转信号
    def __init__(self):
        super(randomWindow, self).__init__()
        self.setupUi(self)
        self.setWindowTitle("睿课人脸识别课堂考勤系统v2.0")
        self.setWindowIcon(QIcon('picture/Logo_2Max.png'))
        self.homeButton.clicked.connect(self.gohomemain)
        self.homeButton.clicked.connect(self.close)
        self.randomButton.clicked.connect(self.get_random)
        self.changeButton.clicked.connect(self.get_change)
        self.backButton.clicked.connect(self.get_back)
    def get_random(self):
        db = pymysql.connect(host='localhost', port=3306, user='root', password="369852147", database="facerecognition")
        cursor = db.cursor()
        sql = "SELECT id FROM punch WHERE state='1'"
        cursor.execute(sql)
        data = cursor.fetchall()
        randomlist=[]
        i=0
        while i < int(len(data)):
            randomlist.append(str(data[i][0]))
            i+=1
        index =random.randint(0, len(randomlist) - 1)
        self.random_idlabel.setText(str( randomlist[index]))
        self.id_lineEdit.setText(str(randomlist[index]))
        sql1 = "SELECT cls,name,sex,attendance FROM student WHERE id="+randomlist[index]
        cursor.execute(sql1)
        data_1 = cursor.fetchall()
        sql2 = "SELECT record FROM record "
        cursor.execute(sql2)
        records = cursor.fetchall()
        self.cls_lineEdit.setText(str(data_1[0][0]))
        self.name_lineEdit.setText(str(data_1[0][1]))
        self.sexlineEdit.setText(str(data_1[0][2]))
        self.att_lineEdit.setText(str(data_1[0][3])+'次')
        attendance = int(data_1[0][3])
        record = int(records[0][0])
        record = (attendance/record)*100
        record = Decimal(record).quantize(Decimal("0.01"), rounding="ROUND_HALF_UP")
        self.rer_lineEdit.setText(str(record)+'%')
        cursor.close()
        db.close()
    def get_change(self):
        db = pymysql.connect(host='localhost', port=3306, user='root', password="369852147", database="facerecognition")
        cursor = db.cursor()
        id = str(self.id_lineEdit.text())
        if id == "--" or id == "":
            QMessageBox.information(self, "睿课", "error:变更到课状态操作失败，没有可以操作的对象！")
            return
        else:
            sql = "update punch set state=0 where id="+id
            sql1 = "update student set attendance=attendance-1 where id="+id
            cursor.execute(sql)
            cursor.execute(sql1)
            db.commit()
            cursor.close()
            db.close()
            QMessageBox.information(self, "睿课", "Tips:变更到课状态操作成功，该生本课时已经标记为缺勤！")
    def get_back(self):
        db = pymysql.connect(host='localhost', port=3306, user='root', password="369852147", database="facerecognition")
        cursor = db.cursor()
        id = str(self.id_lineEdit.text())
        if id == "--" or id == "":
            QMessageBox.information(self, "睿课", "error:撤销变更到课状态操作失败，没有可以操作的对象！")
            return
        else:
            sql = "update punch set state=1 where id=" + id
            sql1 = "update student set attendance=attendance+1 where id=" + id
            cursor.execute(sql)
            cursor.execute(sql1)
            db.commit()
            cursor.close()
            db.close()
            QMessageBox.information(self, "睿课", "Tips:撤销变更到课状态成功，该生本课时已经标记为到课！")
    def gohomemain(self):
        self.switch_homemain.emit()

# 使用指南窗口
class useguideWindow(QtWidgets.QMainWindow,  use_ui):
    switch_homemain = QtCore.pyqtSignal()  # 回主页面跳转信号
    def __init__(self):
        super(useguideWindow, self).__init__()
        self.setupUi(self)
        self.setWindowTitle("睿课人脸识别课堂考勤系统v2.0")
        self.setWindowIcon(QIcon('picture/Logo_2Max.png'))
        self.homepushButton.clicked.connect(self.gohomemain)
        self.homepushButton.clicked.connect(self.close)
    def gohomemain(self):
        self.switch_homemain.emit()

# 融媒体_1窗口
class financialmediaWindow(QtWidgets.QMainWindow,  financialmedia_ui):
    switch_homemain = QtCore.pyqtSignal()  # 回主页面跳转信号
    def __init__(self):
        super(financialmediaWindow, self).__init__()
        self.setupUi(self)
        self.setWindowTitle("睿课人脸识别课堂考勤系统v2.0")
        self.setWindowIcon(QIcon('picture/Logo_2Max.png'))
        self.homepushButton.clicked.connect(self.gohomemain)
        self.homepushButton.clicked.connect(self.close)
    def gohomemain(self):
        self.switch_homemain.emit()

# 融媒体_2窗口
class financialmediatwoWindow(QtWidgets.QMainWindow,  financialmediatwo_ui):
    switch_homemain = QtCore.pyqtSignal()  # 回主页面跳转信号
    def __init__(self):
        super(financialmediatwoWindow, self).__init__()
        self.setupUi(self)
        self.setWindowTitle("睿课人脸识别课堂考勤系统v2.0")
        self.setWindowIcon(QIcon('picture/Logo_2Max.png'))
        self.pushButton.clicked.connect(self.gohomemain)
        self.pushButton.clicked.connect(self.close)
    def gohomemain(self):
        self.switch_homemain.emit()

# 数据仓储窗口
class datawarehousingWindow(QtWidgets.QMainWindow, data_ui):
    switch_homemain = QtCore.pyqtSignal()  # 回主页面跳转信号
    def __init__(self):
        super(datawarehousingWindow, self).__init__()
        self.setupUi(self)
        self.setWindowTitle("睿课人脸识别课堂考勤系统v2.0")
        self.setWindowIcon(QIcon('picture/Logo_2Max.png'))
        self.changeButton.clicked.connect(self.change)
        self.deleteButton.clicked.connect(self.delete)
        self.homepushButton.clicked.connect(self.gohomemain)
        self.homepushButton.clicked.connect(self.close)
    def accountverification(self):
        s_id = str(self.idlineEdit.text())
        s_name = str(self.pwdlineEdit.text())
        db = pymysql.connect(host='localhost', port=3306, user='root', password="369852147", database="facerecognition")
        cursor = db.cursor()
        sql = 'SELECT id,name FROM student'
        cursor.execute(sql)
        data = cursor.fetchall()
        cursor.close()
        db.close()
        i = 0
        if s_id == "" or s_name == "":
            QMessageBox.information(self, "睿课", "白小泽不允许你变更信息操作，请完成校验账户信息(⊙o⊙)？")
            return
        elif s_id != "" and s_name != "":
            while i < int(len(data)):
                if str(data[i][0]) == s_id and str(data[i][1]) == s_name:
                    door = 1
                    checklist.append(s_id)
                    return door
                i += 1
            QMessageBox.information(self, "睿课", "白小泽经过努力核验没能找到您输入的信息，仔您细核对一下吧！")

    def change(self):
        db = pymysql.connect(host='localhost', port=3306, user='root', password="369852147", database="facerecognition")
        cursor = db.cursor()
        door = self. accountverification()
        s_college = str(self.collegelineEdit.text())
        s_major = str(self.majorlineEdit.text())
        s_cls = str(self.clslineEdit.text())
        s_name = str(self.namelineEdit.text())
        s_email = str(self.emaillineEdit.text())
        s_phone = str(self.phonelineEdit.text())
        door_1 = 0
        while door:
            if len(checklist) == 1:
                QMessageBox.information(self, "睿课", "白小泽校验账户信息成功，可以开始操作编辑数据信息了！")
                QMessageBox.information(self, "睿课", "白小泽提示您在一个区域内的信息项是关联的，必须填写不可以有空项哦~")
                checklist.append(door)
                return
            if s_college!="" and s_major!="":
                sql = "SELECT * FROM student WHERE id=" + str(checklist[0])
                cursor.execute(sql)
                data = cursor.fetchall()
                sql1 = "DELETE FROM student WHERE id=" + str(checklist[0])
                cursor.execute(sql1)
                sql2 ="insert into student values('{}', '{}','{}','{}','{}','{}','{}','{}','{}')".format(data[0][0],\
                     data[0][1], data[0][2],data[0][3], s_college, s_major, data[0][6],data[0][7], data[0][8])
                cursor.execute(sql2)
                db.commit()  # 提交数据
                door_1 = 1
                #QMessageBox.information(self, "睿课", "Tips:白小泽提示您个人信息变更成功了哦~")
                self.collegelineEdit.clear()
                self.majorlineEdit.clear()
            if s_cls != "" and s_name != "":
                sql = "SELECT * FROM student WHERE id=" + str(checklist[0])
                cursor.execute(sql)
                data = cursor.fetchall()
                sql1 = "DELETE FROM student WHERE id=" + str(checklist[0])
                cursor.execute(sql1)
                sql2 ="insert into student values('{}', '{}','{}','{}','{}','{}','{}','{}','{}')".format(data[0][0],\
                     s_name, s_cls,data[0][3], data[0][4],data[0][5], data[0][6],data[0][7], data[0][8])
                cursor.execute(sql2)
                db.commit()  # 提交数据
                door_1 = 1
                #QMessageBox.information(self, "睿课", "Tips:白小泽提示您个人信息变更成功了哦~")
                self.clslineEdit.clear()
                self.namelineEdit.clear()
            if s_phone != "" and s_email != "":
                sql = "SELECT * FROM student WHERE id=" + str(checklist[0])
                cursor.execute(sql)
                data = cursor.fetchall()
                sql1 = "DELETE FROM student WHERE id=" + str(checklist[0])
                cursor.execute(sql1)
                sql2 = "insert into student values('{}', '{}','{}','{}','{}','{}','{}','{}','{}')".format(data[0][0], \
                        data[0][1], data[0][2],data[0][3],data[0][4],data[0][5],s_email,s_phone,data[0][8])
                cursor.execute(sql2)
                db.commit()  # 提交数据
                door_1 = 1
                #QMessageBox.information(self, "睿课", "Tips:白小泽提示您个人信息变更成功了哦~")
                self.emaillineEdit.clear()
                self.phonelineEdit.clear()
                self.emaillineEdit.setText("无")
            if door_1 == 0:
                QMessageBox.information(self, "睿课", "Tips:白小泽检测到您没有进行任何操作哦(⊙o⊙)？")
            else:
                QMessageBox.information(self, "睿课", "Tips:白小泽提示您个人信息变更成功了哦~")
            break
        cursor.close()
        db.close()
    def delete(self):
        db = pymysql.connect(host='localhost', port=3306, user='root', password="369852147", database="facerecognition")
        cursor = db.cursor()
        door = self.accountverification()
        while door:
            if len(checklist) == 1:
                QMessageBox.information(self, "睿课", "白小泽校验账户信息成功，可以开始操作编辑数据信息了！")
                return
            reply = QMessageBox.question(self,
                                         "睿课",
                                         "白小泽提示您删除数据后将不能在参与考勤了，是否删除？",
                                         QMessageBox.Yes | QMessageBox.No)
            if reply == QMessageBox.Yes:
                sql = "DELETE FROM student WHERE id=" + str(checklist[0])
                cursor.execute(sql)
                db.commit()
                cursor.close()
                db.close()
                QMessageBox.information(self, "睿课", "白小泽将您的所属信息全部清空了，数据库中已经找不到您了！")
            break

    def gohomemain(self):
        self.switch_homemain.emit()

# 账户仓储窗口
class accountwarehousingWindow(QtWidgets.QMainWindow,  caccount_ui):
    switch_homemain = QtCore.pyqtSignal()  # 回主页面跳转信号
    def __init__(self):
        super(accountwarehousingWindow, self).__init__()
        self.setupUi(self)
        self.setWindowTitle("睿课人脸识别课堂考勤系统v2.0")
        self.setWindowIcon(QIcon('picture/Logo_2Max.png'))
        self.pwdlineEdit.setEchoMode(QLineEdit.Password)  # 密码隐藏
        self.cpwdEdit.setEchoMode(QLineEdit.Password)  # 密码隐藏
        self.protectButton.clicked.connect(self.get_protect)
        self.cancellationButton.clicked.connect(self.get_cancellation)
        self.cuserButton.clicked.connect(self.get_cuser)
        self.cpwdButton.clicked.connect(self.get_cpwd)
        self.changeButton.clicked.connect(self.get_change)
        self.homepushButton.clicked.connect(self.gohomemain)
        self.homepushButton.clicked.connect(self.close)
    def get_accountverification(self):
        check_tlist.clear()
        user = str(self.userlineEdit.text())
        pwd = str(self.pwdlineEdit.text())
        db = pymysql.connect(host='localhost', port=3306, user='root', password="369852147", database="facerecognition")
        cursor = db.cursor()
        sql1 = 'SELECT t_user,t_pwd,t_id FROM teacher'
        cursor.execute(sql1)
        data = cursor.fetchall()
        cursor.close()
        db.close()
        i = 0
        if user == "" or pwd == "":
            QMessageBox.information(self, "睿课", "白小泽不允许你变更信息操作，请完成校验账户信息(⊙o⊙)？")
            return
        elif user != "" and pwd != "":
            while i < int(len(data)):
                if str(data[i][0]) == user and str(data[i][1]) == pwd:
                    door = 1
                    tid = str(data[i][2])
                    check_tlist.append(tid)
                    return door
                i += 1
            QMessageBox.information(self, "睿课", "白小泽经过努力核验没能找到您输入的信息，仔您细核对一下吧！")
    def get_protect(self):

        db = pymysql.connect(host='localhost', port=3306, user='root', password="369852147", database="facerecognition")
        cursor = db.cursor()
        door = self.get_accountverification()
        while door:
            reply = QMessageBox.question(self,
                                         "睿课",
                                         "白小泽提示您开启账户保护后你将不能在对该账户信息进行任何操作，是否修改？",
                                         QMessageBox.Yes | QMessageBox.No)
            if reply == QMessageBox.Yes:
                sql = "UPDATE teacher SET t_protect='1' WHERE t_id="+check_tlist[0]
                cursor.execute(sql)
                db.commit()
                cursor.close()
                db.close()
                QMessageBox.information(self, "睿课", "白小泽将一直保护你的账户，成功开启保护！")
            break
    def get_cancellation(self):
        db = pymysql.connect(host='localhost', port=3306, user='root', password="369852147", database="facerecognition")
        cursor = db.cursor()
        door = self.get_accountverification()
        while door:
            sql1 = "SELECT t_protect FROM teacher WHERE t_id=" + str(check_tlist[0])
            cursor.execute(sql1)
            data = cursor.fetchall()
            if int(data[0][0]) == 1:
                QMessageBox.information(self, "睿课", "白小泽不允许你注销这个账户，该账户已经开启保护！！")
                return
            else:
                reply = QMessageBox.question(self,
                                    "睿课",
                                    "白小泽提示您注销账户后将不能登录系统了，是否删除？",
                                    QMessageBox.Yes | QMessageBox.No)
                if reply == QMessageBox.Yes:
                    sql = "DELETE FROM teacher WHERE t_id=" + str(check_tlist[0])
                    cursor.execute(sql)
                    db.commit()
                    cursor.close()
                    db.close()
                    QMessageBox.information(self, "睿课", "白小泽将您的所属信息全部清空了，数据库中已经找不到您了！")
                    self.userlineEdit.clear()
                    self.pwdlineEdit.clear()
            break
    def get_cuser(self):
        db = pymysql.connect(host='localhost', port=3306, user='root', password="369852147", database="facerecognition")
        cursor = db.cursor()
        door = self.get_accountverification()
        cuser = str(self.cuserEdit.text())
        door_1=0
        while door:
            sql1 = "SELECT t_protect FROM teacher WHERE t_id=" + str(check_tlist[0])
            cursor.execute(sql1)
            adata = cursor.fetchall()
            if int(adata[0][0]) == 1:
                QMessageBox.information(self, "睿课", "白小泽不允许你注销这个账户，该账户已经开启保护！！")
                return
            if cuser != "":
                sql = "SELECT * FROM teacher WHERE t_id=" + str(check_tlist[0])
                cursor.execute(sql)
                data = cursor.fetchall()
                sql1 = "DELETE FROM teacher WHERE t_id=" + str(check_tlist[0])
                cursor.execute(sql1)
                sql2 = "insert into teacher values('{}', '{}','{}','{}','{}','{}','{}','{}')".format(cuser, \
                        data[0][1], data[0][2], data[0][3], data[0][4], data[0][5], data[0][6], data[0][7])
                cursor.execute(sql2)
                db.commit()  # 提交数据
                door_1 =1
            if door_1 == 0:
                QMessageBox.information(self, "睿课", "白小泽没有检测到替换的账户名，那里空空如也！")
                return
            else:
                QMessageBox.information(self, "睿课", "Tips:白小泽提示您用户名变更成功了哦~")
                self.cuserEdit.clear()
            break


        cursor.close()
        db.close()
    def get_cpwd(self):
        db = pymysql.connect(host='localhost', port=3306, user='root', password="369852147", database="facerecognition")
        cursor = db.cursor()
        door = self.get_accountverification()
        cpwd = str(self.cpwdEdit.text())
        door_1 = 0
        while door:
            sql1 = "SELECT t_protect FROM teacher WHERE t_id=" + str(check_tlist[0])
            cursor.execute(sql1)
            adata = cursor.fetchall()
            if int(adata[0][0]) == 1:
                QMessageBox.information(self, "睿课", "白小泽不允许你操作这个账户，该账户已经开启保护！！")
                return
            if cpwd != "":
                sql = "SELECT * FROM teacher WHERE t_id=" + str(check_tlist[0])
                cursor.execute(sql)
                data = cursor.fetchall()
                sql1 = "DELETE FROM teacher WHERE t_id=" + str(check_tlist[0])
                cursor.execute(sql1)
                sql2 = "insert into teacher values('{}', '{}','{}','{}','{}','{}','{}','{}')".format(data[0][0], \
                         cpwd,data[0][2],data[0][3],data[0][4],data[0][5], data[0][6], data[0][7])
                cursor.execute(sql2)
                db.commit()  # 提交数据
                door_1 = 1
            if door_1 == 0:
                QMessageBox.information(self, "睿课", "白小泽没有检测到要修改的密码，那里空空如也！")
                return
            else:
                QMessageBox.information(self, "睿课", "Tips:白小泽提示您密钥变更成功了哦~")
                self.cpwdEdit.clear()
            break
    def get_change(self):
        db = pymysql.connect(host='localhost', port=3306, user='root', password="369852147", database="facerecognition")
        cursor = db.cursor()
        door = self.get_accountverification()
        cid = str(self.cidEdit.text())
        cname = str(self.cnameEdit.text())
        ccollege = str(self.ccollegeEdit.text())
        door_1 = 0
        while door:
            sql1 = "SELECT t_protect FROM teacher WHERE t_id=" + str(check_tlist[0])
            cursor.execute(sql1)
            adata = cursor.fetchall()
            if int(adata[0][0]) == 1:
                QMessageBox.information(self, "睿课", "白小泽不允许你操作这个账户，该账户已经开启保护！！")
                return
            if cid != "" and cname != "" and ccollege != "":
                sql = "SELECT * FROM teacher WHERE t_id=" + str(check_tlist[0])
                cursor.execute(sql)
                data = cursor.fetchall()
                sql1 = "DELETE FROM teacher WHERE t_id=" + str(check_tlist[0])
                cursor.execute(sql1)
                sql2 = "insert into teacher values('{}', '{}','{}','{}','{}','{}','{}','{}')".format(data[0][0], \
                       data[0][1], cid,cname,data[0][4],data[0][5],ccollege,data[0][7])
                cursor.execute(sql2)
                db.commit()  # 提交数据
                door_1 = 1
            if door_1 == 0:
                QMessageBox.information(self, "睿课", "白小泽提示您在一个区域的信息项是关联的不可以为空，补填空项！")
                return
            else:
                QMessageBox.information(self, "睿课", "Tips:白小泽提示您个人信息变更成功了哦~")
                self.cnameEdit.clear()
                self.cidEdit.clear()
                self.ccollegeEdit.clear()
                self.csexEdit.setText("-不可变更-")
                self.cschoolEdit.setText("-不可变更-")
            break




    def gohomemain(self):
        self.switch_homemain.emit()
# 利用一个控制器来控制页面的跳转
class Controller:
    def __init__(self):
        pass
    # 跳转到进入窗口
    def show_jinru(self):
        self.jinru = jinruWindow()
        self.jinru.switch_singin.connect(self.show_singin)
        self.jinru.show()
    # 跳转到登录窗口, 注意关闭原页面
    def show_singin(self):
        self.singin =singinWindow()
        self.singin.switch_main.connect(self.show_main)
        self.singin.switch_registerone.connect(self.show_registerone)
        self.jinru.close()
        self.singin.show()

    # 跳转到注册窗口_1, 注意关闭原页面
    def show_registerone(self):
        self.registerone = registeroneWindow()
        self.registerone.switch_registertwo.connect(self.show_registertwo)
        self.registerone.switch_singin.connect(self.show_singin)
        self.singin.close()
        self.registerone.show()

    # 跳转到注册窗口_2, 注意关闭原页面
    def show_registertwo(self):
        self.registertwo = registertwoWindow()
        self.registertwo.switch_singin.connect(self.show_singin)
        self.registerone.close()
        self.registertwo.show()

    # 跳转到主窗口, 注意关闭原页面
    def show_main(self):
        self.main = mainWindow()
        self.main.switch_punch.connect(self.show_punch)
        self.main.switch_collection.connect(self.show_collection)
        self.main.switch_feedback.connect(self.show_feedback)
        self.main.switch_random.connect(self.show_random)
        self.main.switch_use.connect(self.show_use)
        self.main.switch_financialmedia.connect(self.show_financialmedia)
        self.main.switch_financialmediatwo.connect(self.show_financialmediatwo)
        self.main.switch_datawarehousing.connect(self.show_datawarehousing)
        self.main.switch_accountwarehousing.connect(self.show_accountwarehousing)
        self.main.switch_dataanalysis.connect(self.show_dataanalysis)
        self.singin.close()
        self.main.show()

    # 跳转到考勤窗口, 注意关闭原页面
    def show_punch(self):
        self.punch = punchWindow()
        self.punch.switch_homemain.connect(self.show_main)
        self.main.close()
        self.punch.show()

    # 跳转到信息采集窗口, 注意关闭原页面
    def show_collection(self):
            self.collection = collectionWindow()
            self.collection.switch_homemain.connect(self.show_main)
            self.main.close()
            self.collection.show()

    # 跳转到信息采集窗口, 注意关闭原页面
    def show_feedback(self):
        self.feedback = feedbackWindow()
        self.feedback.switch_homemain.connect(self.show_main)
        self.main.close()
        self.feedback.show()

    # 跳转到随机抽检窗口, 注意关闭原页面
    def show_random(self):
        self.random = randomWindow()
        self.random.switch_homemain.connect(self.show_main)
        self.main.close()
        self.random.show()

    #跳转到使用窗口, 注意关闭原页面
    def show_use(self):
        self.use = useguideWindow()
        self.use.switch_homemain.connect(self.show_main)
        self.main.close()
        self.use.show()
        # 跳转到使用窗口, 注意关闭原页面

    # 跳转到融媒体_1窗口, 注意关闭原页面
    def show_financialmedia(self):
        self.financialmedia = financialmediaWindow()
        self.financialmedia.switch_homemain.connect(self.show_main)
        self.main.close()
        self.financialmedia.show()

    # 跳转到融媒体_1窗口, 注意关闭原页面
    def show_financialmediatwo(self):
        self.financialmediatwo = financialmediatwoWindow()
        self.financialmediatwo.switch_homemain.connect(self.show_main)
        self.main.close()
        self.financialmediatwo.show()

    # 跳转数据仓储窗口, 注意关闭原页面
    def show_datawarehousing(self):
        self.datawarehousing = datawarehousingWindow()
        self.datawarehousing.switch_homemain.connect(self.show_main)
        self.main.close()
        self.datawarehousing.show()

    # 跳转数据仓储窗口, 注意关闭原页面
    def show_accountwarehousing(self):
        self.accountwarehousing = accountwarehousingWindow()
        self.accountwarehousing.switch_homemain.connect(self.show_main)
        self.main.close()
        self.accountwarehousing.show()

    # 跳转数据分析窗口, 注意关闭原页面
    def show_dataanalysis(self):
        self.dataanalysis = dataanalysisWindow()
        self.dataanalysis.switch_homemain.connect(self.show_main)
        self.main.close()
        self.dataanalysis.show()

def main():
    app = QtWidgets.QApplication(sys.argv)
    controller = Controller() # 控制器实例,,
    controller.show_jinru() # 默认展示的进入页面

    sys.exit(app.exec_())

if __name__ == '__main__':
    main()